﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace msBsc.WebUi.Custom
{
    public partial class wfCustManager : msBsc.Cls.BPCustom
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                doShowRateGrid("", "", "");
            }
        }

        private void doShowRateGrid(string CurrPageNum, string strPageRowsCount, string strSort)
        {
            using (msBsc.AppLogic.DataAlc.CBizShpOrderRate oCDbAccess = new msBsc.AppLogic.DataAlc.CBizShpOrderRate())
            {
                string strSql = @"
    SELECT
    A.ORDER_FORM_ID
    ,A.ORDER_FORM_NO
    ,A.INITIAL_DT
    ,A.TRADE_STATUS_TXT
    ,A.BUY_MEMO
    ,A.PAYABLE_AMT
    ,A.RCV_SCORE_QTY
    ,A.LOGISTICS_AMT
    ,A.COMM_TENANT_ID
    ,A.COMM_TENANT_NME
    ,A.COMM_USER_NME
    ,B.GOODS_ID
    ,B.GOODS_NME
    ,B.IMG_URL
    FROM SHP_ORDER_FORM A 
    LEFT OUTER JOIN SHP_ORDER_FORM_LIST B ON A.ORDER_FORM_ID=B.ORDER_FORM_ID
    WHERE
    (A.TRADE_STATUS_TXT<>'交易成功' AND A.TRADE_STATUS_TXT<>'交易关闭')
    AND (A.USER_NME='" + msBsc.SvRef.UserInfo.Operator + @"')
    "; 

                System.Data.DataSet ds = oCDbAccess.DataObj.QueryBySQL(strSql);
                string strjsontem1 = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], ""
                    , "INITIAL_DT,ORDER_FORM_ID,ORDER_FORM_NO,TRADE_STATUS_TXT,BUY_MEMO,PAYABLE_AMT,RCV_SCORE_QTY,LOGISTICS_AMT,COMM_TENANT_ID,COMM_TENANT_NME,COMM_USER_NME "
                    , (CurrPageNum == string.Empty ? 1 : int.Parse(CurrPageNum))
                    , (strPageRowsCount == string.Empty ? 200 : int.Parse(strPageRowsCount))
                    , (strSort == string.Empty ? "INITIAL_DT DESC" : strSort));
                this.ExecJScript(@" var data= " + strjsontem1 + @" ; 
                updateOrderTableHtml( data);");
            }
        }

        public string GetCustInfo()
        {
            StringBuilder sbRet = new StringBuilder();
            string strEmail = "", strTel = "", strGrade = "", strCarItem = "0";


            string strimgtm = "/themes/Style1/Image/u_head_110x110.png"; 
            using (Epm.AppLogic.Framework.CDbAccess oCDbAccess = new Epm.AppLogic.Framework.CDbAccess())
            {
                System.Data.DataSet dst = oCDbAccess.QueryBySQL("SELECT A.E_MAIL,A.TEL,B.LOGO_IMG_URL,B.CUST_GRADE_CID,B.SCORE_QTY,B.CHARGE_AMT FROM SYS_USER A LEFT OUTER JOIN SHP_CUSTOMER_INFO B ON A.USER_NME = B.USER_NME WHERE A.USER_NME='" + msBsc.SvRef.UserInfo.Operator + "'");
                if (dst.Tables[0].Rows.Count > 0)
                {
                    strEmail = dst.Tables[0].Rows[0]["E_MAIL"].ToString();
                    strTel = dst.Tables[0].Rows[0]["TEL"].ToString();
                    strGrade = dst.Tables[0].Rows[0]["CUST_GRADE_CID"].ToString();
                    if (dst.Tables[0].Rows[0]["LOGO_IMG_URL"].ToString() != string.Empty)
                    {
                        strimgtm = dst.Tables[0].Rows[0]["LOGO_IMG_URL"].ToString();
                    }
                }
                this.ExecJScript("$('#divAccountScore').html('" + dst.Tables[0].Rows[0]["SCORE_QTY"].ToString() + "');");
                this.ExecJScript("$('#divAccountAmt').html('" + dst.Tables[0].Rows[0]["CHARGE_AMT"].ToString() + "');");
                dst = oCDbAccess.QueryBySQL("SELECT count(*) as s_count from SHP_CUSTOMER_CART where USER_NME ='" + msBsc.SvRef.UserInfo.Operator + "'");
                if (dst.Tables[0].Rows.Count > 0)
                {
                    strCarItem = dst.Tables[0].Rows[0]["s_count"].ToString();
                }
            }
            string strPayc = "0", strReceiptc = "0", strReiew = "0";
            using (msBsc.AppLogic.DataAlc.CBizShpCustomerInfo odataobj = new AppLogic.DataAlc.CBizShpCustomerInfo())
            {
                System.Data.DataSet ds = odataobj.SelectUserStatistic(msBsc.SvRef.UserInfo.Operator);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    strPayc = ds.Tables[0].Rows[0]["WAIT_PAY_COUNT"].ToString();
                    strReceiptc = ds.Tables[0].Rows[0]["WAIT_RECEIPT_COUNT"].ToString();
                    strReiew = ds.Tables[0].Rows[0]["WAIT_REVIEW_COUNT"].ToString(); 
                }
            }
            sbRet.Append(@"
        <div id=""uHeadImgWrap"">
            <img id=""uHeadImg"" src="""+strimgtm+@""">
        </div>
        <div id=""uInfoShow"">
        <div style=""height: 30px; line-height: 30px; padding-top: 5px;"">
            <font style=""font-size: 16px; font-weight: bold;"">" + msBsc.SvRef.UserInfo.Operator + @"</font> <font style=""font-size: 14px;
                color: #ea2e49; font-weight: bold; font-style: italic;"">&nbsp; &nbsp;" + strGrade + @"</font>
            <font style=""color: #777;"">会员</font>
        </div>
        <div style=""height: 28px; line-height: 28px; color: #777;"">
            <span>绑定邮箱：</span> <span>" + strEmail + @"</span>
        </div>
        <div style=""height: 38px; line-height: 28px; color: #777; border-bottom: 1px dashed #ccc;"">
            <span>绑定手机：</span> <span>" + strTel + @"</span>
        </div>
        <div id=""uOrderCount"">
            <a href=""/c_CustCart.htm"" target=""target"">购物车(<span class=""cartNumCount"" style=""padding: 0px;color:#f40;"">" + strCarItem + @"</span>)</a>
            <a href=""/c_CustBought.htm"">待支付(<span   style=""color:#f40;"">" + strPayc + @"</span>)</a> <a href=""/c_CustBought.htm"">待确认收货(<span   style=""color:#f40;"">" + strReceiptc + @"</span>)</a> <a href=""/c_CustBought.htm"">待评价(<span   style=""color:#f40;"">" + strReiew + @"</span>)</a>
        </div>
        </div>");
            return sbRet.ToString();
        }

    }
}